<template>
    <div>
        <breadcrumb :routerList="routerList"></breadcrumb>
        <searchAre :classList="classList" :supplierList="supplier_list" @searchClick="searchClick"></searchAre>
        <buttonAre :tableSelect="tableSelect" @refreshTableFun="refreshTableFun"></buttonAre>
        <goodsTable :goodsList="goodsList" @tableSelectChange="tableSelectChange" @refreshTableFun="refreshTableFun"></goodsTable>
        <paginationAre :total="total" @currentChange="currentChange"></paginationAre>
    </div>
</template>

<script>
import breadcrumb from '@/components/breadcrumb.vue'
import searchAre from '@/components/goodsAre/searchAre.vue'
import buttonAre from '@/components/goodsAre/buttonAre.vue'
import goodsTable from '@/components/goodsAre/goodsTable.vue'
import paginationAre from '@/components/paginationAre.vue'

export default {
    components: {breadcrumb,searchAre,buttonAre,goodsTable,paginationAre},
    data(){
        return {
            routerList: [
                {
                    name: '商品管理',
                    path: ''
                },
                {
                    name: '商品列表',
                    path: ''
                },
            ],
			supplier_id:this.$store.state.supplier_id,
			supplier_list:[],
            classList: [],
            goodsList: [],
            page: 1,
            status: 10,
            oneClassId: '',
            twoClassId: '',
            goodsName: '',
            tj: 10 ,
            total: 0,
            tableSelect: []
        }
    },
    async created(){
		this.getSupplierList();
        await this.getClass();
        this.getGoodsList();
    },
    methods:{
		async getSupplierList(){
			let res = await this.$Http.getSupplier()
			this.supplier_list = res.list;
		},
        async getClass(){
            let res = await this.$Http.getOneClassList()
            if(res.length!=0){
                for(let i in res){
                    let two = await this.$Http.getTwoClassList({two_class_id: res[i].id})
                    if(two.length!=0){
                        res[i].children = two
                    }
                }
                this.classList = res
            }
        },
        async getGoodsList(){
            let res = await this.$Http.getGoodsList({
                p: this.page,num: this.$store.state.pageNum,status: this.status,
                supplier_id: this.supplier_id,
                one_class_id: this.oneClassId,two_class_id: this.twoClassId,
                product_name: this.goodsName,
                tj: this.tj
            })
            // console.log(res);
            if(res.list.length!=0){
                this.goodsList = res.list
                this.total = Number(res.count)
            }else{
                this.goodsList = []
                this.total = 0
            }
        },
        currentChange(currentPage){
            this.page = currentPage
            this.getGoodsList()
        },
        searchClick(oneClassId,twoClassId,status,goodsName,supplierId){
            console.log(oneClassId, twoClassId, status, goodsName, supplierId, this.supplier_id)
            this.oneClassId = oneClassId
            this.twoClassId = twoClassId
            if(status){
                this.status = status
            }
			this.supplier_id = supplierId ? supplierId : this.supplier_id
            this.goodsName = goodsName
            console.log(oneClassId,twoClassId,status,goodsName, this.supplier_id)
            this.getGoodsList()
        },
        tableSelectChange(list){
            this.tableSelect = list
        },
        refreshTableFun(){
            this.getGoodsList()
        }
    }
}
</script>

<style>

</style>
